package com.wzw.springboot.principle.use.security.infrastructure.handle;

import com.wzw.springboot.principle.mvc.handler.ServletHandler;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 禁止访问处理逻辑 权限不足
 *
 * @author Wangzhiwen
 */
@Component
public class CustomizedAccessDeniedHandler implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
        String message = accessDeniedException.getMessage();
        ServletHandler.write(response, "用户权限不足" + message);
    }
}
